﻿
<!--_meta 作为公共模版分离出去-->
{include file="public/_meta"}

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 产品管理 <span class="c-gray en">&gt;</span> 产品分类 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<span style="color: red;">*点击分类名称可立即删除</span>
<table class="table">
	<tr>
		<td width="200" class="va-t"><ul id="treeDemo" class="ztree"></ul></td>
		<td class="va-t"><iframe ID="testIframe" Name="testIframe" FRAMEBORDER=0 SCROLLING=AUTO width=100%  height=390px SRC="{:url('product/add_product_category')}"></iframe></td>
	</tr>
</table>

<!--_footer 作为公共模版分离出去-->
{include file="public/_footer"}

<script type="text/javascript">
	/*var zNodes =[
		{ id:1, pId:0, name:"一级分类", open:true},
		{ id:11, pId:1, name:"二级分类"},
		{ id:111, pId:11, name:"三级分类"},
		{ id:112, pId:11, name:"三级分类"},
		{ id:113, pId:11, name:"三级分类"},
		{ id:114, pId:11, name:"三级分类"},
		{ id:115, pId:11, name:"三级分类"},
		{ id:12, pId:1, name:"二级分类 1-2"},
		{ id:121, pId:12, name:"三级分类 1-2-1"},
		{ id:122, pId:12, name:"三级分类 1-2-2"},
	];*/
	var zNodes;
	$.ajax({
		url : "{:url('product/product_category_ajax')}",
		type : 'get',
		dataType : 'json',
		async : false,
		success : function(data){
			zNodes = data;
		}
	});
var setting = {
	view: {
		dblClickExpand: false,
		showLine: false,
		selectedMulti: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pid",
			rootPId: ""
		}
	},
	callback: {
		beforeClick: function(treeId, treeNode) {
			$.ajax({
				url : "{:url('product/del_product_category_ajax')}",
				type : 'get',
				dataType : 'json',
				async : false,
				data : {id:treeNode.id},
				success : function(data){
					if(data == 1){
						layer.msg('删除子级分类成功!',{icon: 6,time:1000});
						setTimeout(jump,1000);
						function jump(){
							window.location.replace(location.href);
						}
					}else if(data == 0){
						layer.msg('删除子级分类失败!',{icon: 5,time:1000});
					}else if(data == 2){
						layer.msg('分类下面还有子分类不能删除!',{icon: 5,time:1000});
					}
				}
			});
		}
	}
};

var code;
		
function showCode(str) {
	if (!code) code = $("#code");
	code.empty();
	code.append("<li>"+str+"</li>");
}
		
$(document).ready(function(){
	var t = $("#treeDemo");
	t = $.fn.zTree.init(t, setting, zNodes);
	demoIframe = $("#testIframe");
	//demoIframe.on("load", loadReady);
	var zTree = $.fn.zTree.getZTreeObj("tree");
	//zTree.selectNode(zTree.getNodeByParam("id",'11'));
});
</script>
